﻿namespace HRM.CORE.REPORT
{
    using DevExpress.Utils;
    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    using HRM.CORE;
    
    
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Printing;

    public class rptTraining : XtraReport
    {
        private BottomMarginBand BottomMargin;
        private IContainer components;
        private int count;
        private DetailBand Detail;
        private GroupHeaderBand GroupHeader1;
        private HRM_TRAINING l_Training;
        private DateTime m_FromDate;
        private DateTime m_ToDate;
        private PageFooterBand PageFooter;
        private XRPictureBox ptLogo;
        private ReportHeaderBand ReportHeader;
        private TopMarginBand TopMargin;
        private XRLabel txtCompany;
        private XRTableCell txtEmployees;
        private XRTableCell txtRewardCode;
        private XRLabel txtTime;
        private XRTableCell xrCellDecideDate;
        private XRTableCell xrCellDecideNumber;
        private XRTableCell xrCellForm;
        private XRTableCell xrCellReason;
        private XRTableCell xrCelNumeric;
        private XRLabel xrLabel1;
        private XRTableCell xrTableCell1;
        private XRTableCell xrTableCell2;
        private XRTableCell xrTableCell3;
        private XRTableRow xrTableRow1;
        private XRTableRow xrTableRow2;
        private XRTable xrTblReward;
        private XRTableCell xrTblRewardCell1;
        private XRTableCell xrTblRewardCell2;
        private XRTableCell xrTblRewardCell3;
        private XRTableCell xrTblRewardCell4;
        private XRTableCell xrTblRewardCell5;
        private XRTableCell xrTblRewardCell6;
        private XRTable xrTblRewardTitle;

        public rptTraining()
        {
            this.components = null;
            this.count = 0;
            this.m_FromDate = DateTime.Now;
            this.m_ToDate = DateTime.Now;
            this.l_Training = new HRM_TRAINING();
            this.InitializeComponent();
            this.LoadData();
        }

        public rptTraining(DateTime FromDate, DateTime ToDate)
        {
            this.components = null;
            this.count = 0;
            this.m_FromDate = DateTime.Now;
            this.m_ToDate = DateTime.Now;
            this.l_Training = new HRM_TRAINING();
            this.InitializeComponent();
            this.m_FromDate = FromDate;
            this.m_ToDate = ToDate;
            this.txtTime.Text = "(Từ ng\x00e0y " + this.m_FromDate.ToShortDateString() + " đến ng\x00e0y " + this.m_ToDate.ToShortDateString() + ")";
            this.LoadDataByDate();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.Detail = new DetailBand();
            this.xrTblReward = new XRTable();
            this.xrTableRow2 = new XRTableRow();
            this.xrCelNumeric = new XRTableCell();
            this.txtRewardCode = new XRTableCell();
            this.xrCellDecideNumber = new XRTableCell();
            this.xrCellDecideDate = new XRTableCell();
            this.xrCellReason = new XRTableCell();
            this.txtEmployees = new XRTableCell();
            this.xrCellForm = new XRTableCell();
            this.xrTableCell3 = new XRTableCell();
            this.xrTblRewardTitle = new XRTable();
            this.xrTableRow1 = new XRTableRow();
            this.xrTblRewardCell1 = new XRTableCell();
            this.xrTableCell1 = new XRTableCell();
            this.xrTblRewardCell2 = new XRTableCell();
            this.xrTblRewardCell3 = new XRTableCell();
            this.xrTblRewardCell4 = new XRTableCell();
            this.xrTblRewardCell5 = new XRTableCell();
            this.xrTblRewardCell6 = new XRTableCell();
            this.xrTableCell2 = new XRTableCell();
            this.TopMargin = new TopMarginBand();
            this.BottomMargin = new BottomMarginBand();
            this.xrLabel1 = new XRLabel();
            this.ptLogo = new XRPictureBox();
            this.ReportHeader = new ReportHeaderBand();
            this.txtCompany = new XRLabel();
            this.txtTime = new XRLabel();
            this.PageFooter = new PageFooterBand();
            this.GroupHeader1 = new GroupHeaderBand();
            this.xrTblReward.BeginInit();
            this.xrTblRewardTitle.BeginInit();
            this.BeginInit();
            this.Detail.Controls.AddRange(new XRControl[] { this.xrTblReward });
            this.Detail.HeightF = 47.70829f;
            this.Detail.Name = "Detail";
            this.Detail.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.Detail.TextAlignment = TextAlignment.TopLeft;
            this.xrTblReward.Borders = BorderSide.Bottom | BorderSide.Right | BorderSide.Left;
            this.xrTblReward.LocationFloat = new PointFloat(0f, 0f);
            this.xrTblReward.Name = "xrTblReward";
            this.xrTblReward.Rows.AddRange(new XRTableRow[] { this.xrTableRow2 });
            this.xrTblReward.SizeF = new SizeF(996.0001f, 47.70829f);
            this.xrTblReward.StylePriority.UseBorders = false;
            this.xrTblReward.StylePriority.UseTextAlignment = false;
            this.xrTblReward.TextAlignment = TextAlignment.MiddleCenter;
            this.xrTableRow2.Cells.AddRange(new XRTableCell[] { this.xrCelNumeric, this.txtRewardCode, this.xrCellDecideNumber, this.xrCellDecideDate, this.xrCellReason, this.txtEmployees, this.xrCellForm, this.xrTableCell3 });
            this.xrTableRow2.Name = "xrTableRow2";
            this.xrTableRow2.Weight = 1.0;
            this.xrCelNumeric.Font = new Font("Times New Roman", 11.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.xrCelNumeric.Name = "xrCelNumeric";
            this.xrCelNumeric.StylePriority.UseFont = false;
            this.xrCelNumeric.StylePriority.UseTextAlignment = false;
            this.xrCelNumeric.TextAlignment = TextAlignment.MiddleCenter;
            this.xrCelNumeric.Weight = 0.22703619887183102;
            this.xrCelNumeric.BeforePrint += new PrintEventHandler(this.xrCelNumeric_BeforePrint);
            this.txtRewardCode.Font = new Font("Times New Roman", 11.25f);
            this.txtRewardCode.Name = "txtRewardCode";
            this.txtRewardCode.StylePriority.UseFont = false;
            this.txtRewardCode.Text = "[TrainingCode]";
            this.txtRewardCode.Weight = 0.46794687895963555;
            this.xrCellDecideNumber.Font = new Font("Times New Roman", 11.25f);
            this.xrCellDecideNumber.Name = "xrCellDecideNumber";
            this.xrCellDecideNumber.StylePriority.UseFont = false;
            this.xrCellDecideNumber.StylePriority.UseTextAlignment = false;
            this.xrCellDecideNumber.Text = "[TrainingName]";
            this.xrCellDecideNumber.TextAlignment = TextAlignment.MiddleCenter;
            this.xrCellDecideNumber.Weight = 0.51144781864118294;
            this.xrCellDecideDate.Font = new Font("Times New Roman", 11.25f);
            this.xrCellDecideDate.Name = "xrCellDecideDate";
            this.xrCellDecideDate.StylePriority.UseFont = false;
            this.xrCellDecideDate.StylePriority.UseTextAlignment = false;
            this.xrCellDecideDate.Text = "[DecideNumber]";
            this.xrCellDecideDate.TextAlignment = TextAlignment.MiddleCenter;
            this.xrCellDecideDate.Weight = 0.3519475415269937;
            this.xrCellReason.Font = new Font("Times New Roman", 11.25f);
            this.xrCellReason.Name = "xrCellReason";
            this.xrCellReason.StylePriority.UseFont = false;
            this.xrCellReason.Text = "[Purpose]";
            this.xrCellReason.Weight = 0.54269439484030269;
            this.txtEmployees.Font = new Font("Times New Roman", 11.25f);
            this.txtEmployees.Name = "txtEmployees";
            this.txtEmployees.StylePriority.UseFont = false;
            this.txtEmployees.StylePriority.UseTextAlignment = false;
            this.txtEmployees.TextAlignment = TextAlignment.MiddleCenter;
            this.txtEmployees.Weight = 0.61644678196769265;
            this.txtEmployees.BeforePrint += new PrintEventHandler(this.xrCellPerson_BeforePrint);
            this.xrCellForm.Font = new Font("Times New Roman", 11.25f);
            this.xrCellForm.Name = "xrCellForm";
            this.xrCellForm.StylePriority.UseFont = false;
            this.xrCellForm.StylePriority.UseTextAlignment = false;
            this.xrCellForm.Text = "[Form]";
            this.xrCellForm.TextAlignment = TextAlignment.MiddleCenter;
            this.xrCellForm.Weight = 0.49594269621966985;
            this.xrTableCell3.Font = new Font("Times New Roman", 11.25f);
            this.xrTableCell3.Name = "xrTableCell3";
            this.xrTableCell3.StylePriority.UseFont = false;
            this.xrTableCell3.Text = "[DecideDate!dd/MM/yyyy]";
            this.xrTableCell3.Weight = 0.40881084650580651;
            this.xrTblRewardTitle.BackColor = Color.Silver;
            this.xrTblRewardTitle.Borders = BorderSide.All;
            this.xrTblRewardTitle.Font = new Font("Times New Roman", 11.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.xrTblRewardTitle.LocationFloat = new PointFloat(0f, 0f);
            this.xrTblRewardTitle.Name = "xrTblRewardTitle";
            this.xrTblRewardTitle.Rows.AddRange(new XRTableRow[] { this.xrTableRow1 });
            this.xrTblRewardTitle.SizeF = new SizeF(996.0001f, 39.58333f);
            this.xrTblRewardTitle.StylePriority.UseBackColor = false;
            this.xrTblRewardTitle.StylePriority.UseBorders = false;
            this.xrTblRewardTitle.StylePriority.UseFont = false;
            this.xrTblRewardTitle.StylePriority.UseTextAlignment = false;
            this.xrTblRewardTitle.TextAlignment = TextAlignment.MiddleCenter;
            this.xrTableRow1.Cells.AddRange(new XRTableCell[] { this.xrTblRewardCell1, this.xrTableCell1, this.xrTblRewardCell2, this.xrTblRewardCell3, this.xrTblRewardCell4, this.xrTblRewardCell5, this.xrTblRewardCell6, this.xrTableCell2 });
            this.xrTableRow1.Name = "xrTableRow1";
            this.xrTableRow1.Weight = 1.0;
            this.xrTblRewardCell1.Name = "xrTblRewardCell1";
            this.xrTblRewardCell1.Text = "STT";
            this.xrTblRewardCell1.Weight = 0.22703640602313807;
            this.xrTableCell1.Name = "xrTableCell1";
            this.xrTableCell1.Text = "M\x00e3 đợt";
            this.xrTableCell1.Weight = 0.46794657210488771;
            this.xrTblRewardCell2.Name = "xrTblRewardCell2";
            this.xrTblRewardCell2.Text = "T\x00ean chương tr\x00ecnh đ\x00e0o tạo";
            this.xrTblRewardCell2.Weight = 0.51144790933318318;
            this.xrTblRewardCell3.Name = "xrTblRewardCell3";
            this.xrTblRewardCell3.Text = "Số quyết định";
            this.xrTblRewardCell3.Weight = 0.35194731087173736;
            this.xrTblRewardCell4.Name = "xrTblRewardCell4";
            this.xrTblRewardCell4.Text = "Mục đ\x00edch đ\x00e0o tạo";
            this.xrTblRewardCell4.Weight = 0.54269428032714817;
            this.xrTblRewardCell5.Name = "xrTblRewardCell5";
            this.xrTblRewardCell5.Text = "Những người được đ\x00e0o tạo trong đợt";
            this.xrTblRewardCell5.Weight = 0.6164464222396383;
            this.xrTblRewardCell6.Name = "xrTblRewardCell6";
            this.xrTblRewardCell6.Text = "H\x00ecnh thức đ\x00e0o tạo";
            this.xrTblRewardCell6.Weight = 0.4959428159189152;
            this.xrTableCell2.Name = "xrTableCell2";
            this.xrTableCell2.Text = "Ng\x00e0y quyết định";
            this.xrTableCell2.Weight = 0.40881086897111263;
            this.TopMargin.HeightF = 46f;
            this.TopMargin.Name = "TopMargin";
            this.TopMargin.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.TopMargin.TextAlignment = TextAlignment.TopLeft;
            this.BottomMargin.HeightF = 51f;
            this.BottomMargin.Name = "BottomMargin";
            this.BottomMargin.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.BottomMargin.TextAlignment = TextAlignment.TopLeft;
            this.xrLabel1.Font = new Font("Times New Roman", 18f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.xrLabel1.LocationFloat = new PointFloat(222.9167f, 25.91664f);
            this.xrLabel1.Name = "xrLabel1";
            this.xrLabel1.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.xrLabel1.SizeF = new SizeF(773.0835f, 31.70829f);
            this.xrLabel1.StylePriority.UseFont = false;
            this.xrLabel1.StylePriority.UseTextAlignment = false;
            this.xrLabel1.Text = "SỔ THEO D\x00d5I Đ\x00c0O TẠO";
            this.xrLabel1.TextAlignment = TextAlignment.MiddleCenter;
            this.ptLogo.LocationFloat = new PointFloat(47.66667f, 0f);
            this.ptLogo.Name = "ptLogo";
            this.ptLogo.SizeF = new SizeF(109.375f, 72.91665f);
            this.ptLogo.Sizing = ImageSizeMode.StretchImage;
            this.ReportHeader.Controls.AddRange(new XRControl[] { this.txtCompany, this.txtTime, this.xrLabel1, this.ptLogo });
            this.ReportHeader.HeightF = 105f;
            this.ReportHeader.Name = "ReportHeader";
            this.txtCompany.Font = new Font("Times New Roman", 12f, FontStyle.Bold);
            this.txtCompany.LocationFloat = new PointFloat(0f, 72.91663f);
            this.txtCompany.Name = "txtCompany";
            this.txtCompany.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtCompany.SizeF = new SizeF(202.6248f, 21.29163f);
            this.txtCompany.StylePriority.UseFont = false;
            this.txtCompany.StylePriority.UseTextAlignment = false;
            this.txtCompany.Text = "Company";
            this.txtCompany.TextAlignment = TextAlignment.MiddleCenter;
            this.txtTime.Font = new Font("Times New Roman", 12f, FontStyle.Italic, GraphicsUnit.Point, 0);
            this.txtTime.LocationFloat = new PointFloat(222.9167f, 57.62494f);
            this.txtTime.Name = "txtTime";
            this.txtTime.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtTime.SizeF = new SizeF(773.0835f, 21.29159f);
            this.txtTime.StylePriority.UseFont = false;
            this.txtTime.StylePriority.UseTextAlignment = false;
            this.txtTime.TextAlignment = TextAlignment.MiddleCenter;
            this.PageFooter.HeightF = 49f;
            this.PageFooter.Name = "PageFooter";
            this.GroupHeader1.Controls.AddRange(new XRControl[] { this.xrTblRewardTitle });
            this.GroupHeader1.HeightF = 39.58334f;
            this.GroupHeader1.Name = "GroupHeader1";
            base.Bands.AddRange(new Band[] { this.Detail, this.TopMargin, this.BottomMargin, this.ReportHeader, this.PageFooter, this.GroupHeader1 });
            base.Landscape = true;
            base.Margins = new Margins(0x65, 0x48, 0x2e, 0x33);
            base.PageHeight = 0x33b;
            base.PageWidth = 0x491;
            base.PaperKind = PaperKind.A4;
            base.Version = "9.3";
            this.BeforePrint += new PrintEventHandler(this.rptTraining_BeforePrint);
            this.xrTblReward.EndInit();
            this.xrTblRewardTitle.EndInit();
            this.EndInit();
        }

        private void LoadData()
        {
            DataSet set = new DataSet();
            DataTable list = new DataTable();
            list = this.l_Training.GetList();
            set.Tables.Add(list);
            base.DataSource = set;
            base.DataMember = list.TableName;
            base.DataAdapter = list;
        }

        private void LoadDataByDate()
        {
            DataSet set = new DataSet();
            DataTable listByDate = new DataTable();
            listByDate = this.l_Training.GetListByDate(this.m_FromDate, this.m_ToDate);
            set.Tables.Add(listByDate);
            base.DataSource = set;
            base.DataMember = listByDate.TableName;
            base.DataAdapter = listByDate;
        }

        private void rptTraining_BeforePrint(object sender, PrintEventArgs e)
        {
            //if (MyInfo.Get(MyEncryption.Encrypt("ERP01", "123654", true)) == "OK")
            {
                this.ptLogo.Image = null;//MyInfo.Photo;
                this.txtCompany.Text = "";//MyInfo.Company;
            }
        }

        private void xrCellPerson_BeforePrint(object sender, PrintEventArgs e)
        {
            HRM_TRAINING_EMPLOYEE hrm_training_employee = new HRM_TRAINING_EMPLOYEE();
            string str = "";
            foreach (DataRow row in hrm_training_employee.GetList(this.txtRewardCode.Text).Rows)
            {
                str = string.Concat(new object[] { str, row["FirstName"], " ", row["LastName"], ";  " });
            }
            this.txtEmployees.Text = str;
        }

        private void xrCelNumeric_BeforePrint(object sender, PrintEventArgs e)
        {
            this.count++;
            this.xrCelNumeric.Text = this.count.ToString();
        }
    }
}

